#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
int main()
{
	int n;
	cin>>n;
	vector<ll> arr(n+1);
	vector<ll> dp(n+1);
	
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	dp[1]=arr[1];
	ll maxn=arr[1];
    ll pre=-0x3f3f;
	for(int i=2;i<=n;i++)
	{
		if(arr[i]>=maxn)
		{
			pre=maxn;
			maxn=arr[i];
		}
		else if(arr[i]>=pre)
		{
			pre=arr[i];
		}
		dp[i]=pre;
	}
	int q;
	cin>>q;
	while(q--)
	{
		int t;
		cin>>t;
		cout<<dp[t]<<endl;
	}
	return 0;
}
